const mongoose = require('mongoose')
mongoose.connect('mongodb://127.0.0.1:27017/bilibili')
mongoose.connection.once('open', async () => {
  const catSchema = new mongoose.Schema({
    name:String,
    age:Number,
    color:String,
    test:mongoose.Schema.Types.Mixed,       //混合类型
    test2:mongoose.Schema.Types.ObjectId,   //对象ID 用于表连接外键
    test3:mongoose.Schema.Types.Decimal128, //高精度数字
  })

  const Cat = mongoose.model('Cat', catSchema)
  Cat.create({name:'小白',age:2,color:'white'}).then(res=>{
    console.log('创建成功',res)
  }).catch(err=>{
    console.log('创建失败',err)
  })

})
mongoose.connection.on('error', () => {  //连接失败的回调
  console.log('连接失败')
})
mongoose.connection.on('close', () => {  //连接关闭的回调
  console.log('连接关闭')
})